package com.csproj.basic.repository;

import com.csproj.basic.domain.FixedReadingDevice;
import com.csproj.basic.repository.custom.FixedReadingDeviceRepositoryCustom;
import org.springframework.stereotype.Repository;

import org.springframework.data.jpa.repository.*;

import java.util.List;
import java.util.Map;


/**
 * Spring Data JPA repository for the FixedReadingDevice entity.
 */
@SuppressWarnings("unused")
@Repository
public interface FixedReadingDeviceRepository extends JpaRepository<FixedReadingDevice, String> , FixedReadingDeviceRepositoryCustom {
    /**
     * 根据ids查询固定读写设备列表信息
     * @author LM
     * @date   2018-09-14
     * @param ids
     * @return
     */
    @Query(" from FixedReadingDevice where deletedFlag = 0 and id in(?1) ")
    List<FixedReadingDevice> findByIds(String[] ids);


    /**
     * 根据ID删除数据
     * @author LM
     * @date   2018-09-14
     * @param id 设备id
     */
    @Modifying
    @Query("UPDATE FixedReadingDevice SET enableFlag = ?2 where id = ?1")
    void updateStatus(String id, boolean enable);

    /**
     * 根据ID删除数据
     * @author LM
     * @date   2018-09-14
     * @param id 机构id
     */
    @Query(" from FixedReadingDevice where deletedFlag = 0 and id = ?1")
    FixedReadingDevice findById(String id);

    /**
     * 根据机构ids，批量固定读写设备信息
     * @param ids
     */
    @Modifying
    @Query(" update FixedReadingDevice set deletedFlag = 1 where id in (?1) ")
    void deleteIds(String[] ids);

    /**
     *
     * 未分配设备数量
     * @return
     */
    @Query(" FROM FixedReadingDevice  where deletedFlag = 0 and siteId is null or siteId = ''")
    List<FixedReadingDevice> findByUnSiteId();

    /**
     * 查询该站点下启用的设备数量
     * @param siteId
     * @param b
     * @return
     */
    @Query(" from FixedReadingDevice where deletedFlag = 0 and siteId = ?1 and enableFlag = ?2  ")
    List<FixedReadingDevice> findBySiteIdAndEnable(String siteId, boolean b);

    FixedReadingDevice findFirstByDeviceNoAndDeletedFlagIsFalse(String deviceNo);
    /**
     * 查询该站点下，已安装设备数量
     * @param siteId
     * @param b
     * @param ib
     * @return
     */
    @Query(" from FixedReadingDevice  where deletedFlag = 0 and siteId = ?1 and enableFlag = ?2 and installFlag = ?3 ")
    List<FixedReadingDevice> findBySiteIdAndInstall(String siteId, boolean b,Boolean ib);
}
